import { ReqUserInfo, ReqLogout } from '@/api';
import { deleteToken } from '@/utils/auth';
const state = {
  userInfo: {},
};

const mutations = {
  //保存用户信息
  SAVE_USER_INFO(state, value) {
    state.userInfo = value;
  },
  DELETE_USER_INFO(state) {
    state.userInfo = {};
  },
};

const actions = {
  //获取用户信息
  async asyncGetUserInfo({ commit }) {
    try {
      let data = await ReqUserInfo();
      // console.log(data);
      commit('SAVE_USER_INFO', data);
    } catch (error) {
      return Promise.reject();
    }
  },
  async asyncDeleteUserInfo({ commit }) {
    try {
      await ReqLogout();
      deleteToken();
      commit('DELETE_USER_INFO');
    } catch (error) {
      return Promise.reject();
    }
  },
};

const getters = {};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters,
};
